home *** CD-ROM | disk | FTP | other *** search
Text File | 1999-06-21 | 2.8 KB | 132 lines | [TEXT/CWIE] |
- // ===========================================================================
- // TerminationUtils.cp ©1999 Eric Traut
- // ===========================================================================
-
- #include "TerminationUtils.h"
-
- #ifndef __MIXEDMODE__
- #include <MixedMode.h>
- #endif
-
- #ifndef __TRAPS__
- #include <Traps.h>
- #endif
-
- #ifndef __OSUTILS__
- #include <OSUtils.h>
- #endif
-
- /* Global and static variables */
- static TearDownProcPtr sTearDownProcs[kMaxTearDownProcs];
- static Boolean sDisableTearDownProcs = false;
-
- static void ExecuteTearDownProcs(void);
-
- extern "C"
- {
- void TerminationProc(void);
- }
-
-
- /*------------------------------------------------------------------
- InitTerminationUtils
-
- This routine initializes the module.
- ------------------------------------------------------------------*/
-
- void
- InitTerminationUtils(void)
- {
- UInt32 curProcIndex;
-
- // Initialize tear-down proc array
- for (curProcIndex = 0; curProcIndex < kMaxTearDownProcs; curProcIndex++)
- sTearDownProcs[curProcIndex] = NULL;
- }
-
-
- /*------------------------------------------------------------------
- DisableTearDownProcs
-
- This routine tells the termination module that the tear-down
- procs are unnecessary because normal termination has occured.
- ------------------------------------------------------------------*/
-
- void
- DisableTearDownProcs(void)
- {
- sDisableTearDownProcs = true;
- }
-
-
- /*------------------------------------------------------------------
- TerminationProc
-
- This routine is the CFM fragment's termination proc.
- ------------------------------------------------------------------*/
-
- void
- TerminationProc(void)
- {
- ExecuteTearDownProcs();
- }
-
-
- /*------------------------------------------------------------------
- ExecuteTearDownProcs
-
- This routine executes all the currently installed tear-down
- procs.
- ------------------------------------------------------------------*/
-
- void
- ExecuteTearDownProcs(void)
- {
- SInt32 curProcIndex;
-
- if (!sDisableTearDownProcs)
- {
- sDisableTearDownProcs = true;
-
- // Find first empty entry in array
- for (curProcIndex = kMaxTearDownProcs - 1; curProcIndex >= 0; curProcIndex--)
- {
- TearDownProcPtr curProc;
-
- curProc = sTearDownProcs[curProcIndex];
-
- // Call the current proc
- if (curProc != NULL)
- (*curProc)();
- }
- }
- }
-
-
- /*------------------------------------------------------------------
- InstallTearDownProc
-
- Parameters:
- In: inProcToCall - native procedure to call on termination
- ------------------------------------------------------------------*/
-
- void
- InstallTearDownProc(TearDownProcPtr inProcToCall)
- {
- UInt32 curProcIndex;
-
- // Find first empty entry in array
- for (curProcIndex = 0; curProcIndex < kMaxTearDownProcs; curProcIndex++)
- {
- if (sTearDownProcs[curProcIndex] == NULL)
- break;
- }
-
- if (curProcIndex < kMaxTearDownProcs)
- sTearDownProcs[curProcIndex] = inProcToCall;
- }
-
-
-
-
-